package com.ljw.food_order_server.controller;


import com.ljw.food_order_server.entity.Food;
import com.ljw.food_order_server.service.impl.FoodServiceImpl;
import com.ljw.food_order_server.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 菜单 前端控制器
 * </p>
 *
 * @author ljw
 * @since 2021-07-31
 */
@RestController
@RequestMapping("/food")
public class FoodController {

    @Autowired
    private FoodServiceImpl foodService;

    /**
     * 根据窗口获取菜品信息
     * url：/food/getInfo
     * @return
     */
    @GetMapping("/getFoodsByWindowId")
    public R getFoodsByWindowId(@RequestParam Integer windowId){
        List<Food> foods = foodService.getFoodsByWindowId(windowId);
        return R.getR().ok(foods);
    }

    /**
     * 根据positionId随机获取一道菜品
     * @return
     */
    @GetMapping("/getFoodRandom")
    public R getFoodRandom(@RequestParam Integer positionId){
        return R.getR().ok(foodService.getFoodRandom(positionId));
    }

    /**
     * 模糊查询
     * @return
     */
    @GetMapping("/getFoodsBlur")
    public R getFoodsBlur(@RequestParam int positionId, @RequestParam String word){
        return R.getR().ok(foodService.getFoodsBlur(positionId, word));
    }

}

